<?php
/** 
 * EGP Framework
 *
 * LICENSE
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 */

!defined('EGP_LIB_DIR') && die('Access Deny!');

/**
 * HTTP 处理
 *
 * @package    classes
 * @author     Akon(番茄红了) <aultoale@gmail.com>
 * @copyright  Copyright (c) 2008 (http://www.tblog.com.cn)
 * @license    http://www.gnu.org/licenses/gpl.html     GPL 3
 */
abstract class EGP_Http
{

    /**
     * 重定向页面
     *
     * @param  string  $url
     */
    public static function redirect($url)
    {
        header("Location: $url");
        die();
    }

    /**
     * 生成 Web 服务器 404 错误
     *
     * @param  string  $message
     */
    public static function _404($message = null)
    {
        @ob_clean();
        //@header("HTTP/1.0 404 Not Found");
        @header("Content-type: text/html; charset=utf-8");
        echo <<<EOF
<title>HTTP/1.0 404 Not Found</title>
<h2>HTTP/1.0 404 Not Found</h2>
<p>非常抱歉，请求的页面不存在。<p>
EOF;
        if (EGP_Core::debug() && !empty($message)) {
            echo "<font color=green>$message</font>";
        }
        die();
    }

    /**
     * 输出无缓存头信息
     *
     */
    public static function noCache() {
        header('Expires: Fri, 14 Mar 1980 20:53:00 GMT');
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        header('Cache-Control: no-cache, must-revalidate');
        header('Pragma: no-cache');
    }

}